package com.easou.ps.dk;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.easou.ps.dk.domain.ABaiduResult;
import com.easou.ps.dk.domain.BaiduResult;
import com.easou.ps.dk.domain.QueryParams;

/**
 * 检查环境，初始化各种配置，包括创建必要的文件夹
 * @author dirk
 *
 */
public class InitConfiger {

	public static QueryParams init() {
		QueryParams qp = new QueryParams();
		
		//从PerWords.txt中获取百度的信息和query词
		setupWords(qp);
		
		return qp;
	}
	public static void setupWords(QueryParams qp){
		List<String> querys = new ArrayList<String>();
		BaiduResult baiduResult = new BaiduResult();
		try {
			File file = new File("./config/PerWords.txt");
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
			String line = "";
			while((line = br.readLine())!=null){
				String[] temp = line.split("@@@");
				if(temp.length==3){
					String query = temp[0];
					String url = temp[1];
					baiduResult.putABaidu(query, url);
					if(!querys.contains(query)){
						querys.add(query);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		qp.setQuerys(querys);
		qp.setBaiduResult(baiduResult);
	}
}
